package com.atguigu.rabbitmq.two;

import com.atguigu.rabbitmq.util.RabbitmqUtil;
import com.rabbitmq.client.Channel;

import java.io.IOException;
import java.util.Scanner;

/**
 * @author codingBee
 * @since 2021/6/22/20:59
 * 生产消息，发送大量消息
 */
public class Task01 {
    //队列名称
    public static final String QUEUE_NAME = "hello";
    //发送大量消息
    public static void main(String[] args) throws IOException {
        Channel chanel = RabbitmqUtil.getChannel();
        //队列的声明
        chanel.queueDeclare(QUEUE_NAME ,Boolean.FALSE,Boolean.FALSE,Boolean.FALSE,null);
        //从控制台中接受信息
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String message = scanner.next();
            /**
             * Publish a message. 发送一个消息
             * Publishing to a non-existent exchange will result in a channel-level
             * protocol exception, which closes the channel.
             * Invocations of <code>Channel#basicPublish</code> will eventually block if a
             * <a href="https://www.rabbitmq.com/alarms.html">resource-driven alarm</a> is in effect.
             * @see com.rabbitmq.client.AMQP.Basic.Publish
             * @see <a href="https://www.rabbitmq.com/alarms.html">Resource-driven alarms</a>
             * @param exchange the exchange to publish the message to  要发送到的交换器
             * @param routingKey the routing key 路由 key
             * @param props other properties for the message - routing headers etc 其他信息的参数，如路由头
             * @param body the message body 消息体
             * @throws java.io.IOException if an error is encountered
             */
            chanel.basicPublish("",QUEUE_NAME,null,message.getBytes());
            System.out.println("发送消息完成");
        }
    }
}
